package com.fire.social.mapper;

import com.fire.social.entity.relationship.Like;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.neo4j.repository.query.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

@Repository
public interface LikeMapper extends Neo4jRepository<Like, Long> {

    @Query("match (user:User) where user.account=$account match (hobby:Hobby) where ID(hobby)=$hobbyId\n" +
            "create (user)-[like:Like]->(hobby) create (user)<-[liked:Like]-(hobby) return count(liked)+count(like)")
    Integer likeHobby(@Param("account") String account, @Param("hobbyId")Long hobbyId);

    @Query("match (user:User) where user.account=$account match (hobby:Hobby) where ID(hobby)=$hobbyid\n" +
            "match (user)-[like:Like]-(hobby) delete like return count(like)")
    Integer unlikeHobby(@Param("account") String account, @Param("hobbyId")Long hobbyId);

}
